package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.SpecialService;
import org.dom4j.Element;

/**
 * 划解专户接口
 *
 * @auther dinggaofei
 * @Date 2023/2/2 11:40
 */
public class PaySpecialApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getPaySpecial")) { // 获取化解专户
            String billNum = body.elementText("billnum");
            if (billNum == null || billNum.length() == 0) {
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");
            }
            SpecialService specialService = (SpecialService) SpringContextUtil.getBean("specialService");
            return specialService.getPaySpecial(billNum);
        } else if (head.equals("setSpecialPayInfo")) { //  化解专户单据收款
            String billnum = body.elementText("billnum");
            String paybankdt = body.elementText("paybankdt");
            String bankaffirm = body.elementText("bankaffirm");
            String bankstation = body.elementText("bankstation");
            SpecialService specialService = (SpecialService) SpringContextUtil.getBean("specialService");
            BaseResult result = specialService.setSpecialPayInfo(billnum, bankaffirm, paybankdt, bankstation, "00");
            int n = (result.isSuccess()) ? 1 : 0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        }
        return null;
    }
}
